home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
language
/
dl_exsrc.zoo
/
makepath.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-07-03
|
1KB
|
69 lines
#include <string.h>
#include "extras.h"
/*
char *_makepath(char *dst, *drive, *path, *file, *ext)
Build the <dst> filename from component parts. Returns <dst>.
This function is basically in inverse of _splitpath(), and will
accept the components parsed by _splitpath() as input. It will
also allow a little more flexibility in that it will treat any
component which is a NULL pointer as an empty field, and the
<path> component may optionally have a trailing '\'.
*/
#define DEFAULT_PATHSEP '/'
char *_makepath(dst, drive, path, file, ext)
char *dst;
const char *drive, *path, *file, *ext;
{
register char *s = dst;
register const char *t;
register char sep;
if (drive) {
t = drive;
while (*s++ = *t++)
continue;
s--;
if (s[-1] == '/' || s[-1] == '\\')
*--s = '\0';
}
if (path) {
t = strpbrk(path, "/\\");
if (t)
sep = *t;
else
sep = DEFAULT_PATHSEP;
t = path;
if (drive && *t != '/' && *t != '\\')
*s++ = sep;
while (*s++ = *t++)
continue;
s--;
if (s[-1] != '/' && s[-1] != '\\')
*s++ = sep;
} else if (drive) {
*s++ = DEFAULT_PATHSEP;
}
if (file) {
t = file;
while (*s++ = *t++)
continue;
s--;
}
if (ext) {
*s++ = '.';
t = ext;
while (*s++ = *t++)
continue;
s--;
}
*s = '\0';
return dst;
}